const prefix = process.env.VUE_APP_STORAGE_PREFIX;
const tokenName = prefix + 'token';
const userIdName = prefix + 'userId';
const userInfoName = prefix + 'userInfo';
const publicConfigName = prefix + 'publicConfig';
const officesListName = prefix + 'officesList';
const roleLevelName = prefix + 'roleLevel';
export function getToken() {
    return localStorage.getItem(tokenName);
}

export function setToken(token) {
    return localStorage.setItem(tokenName, token)
}

export function getRole() {
    return localStorage.getItem(roleLevelName);
}

export function setRole(role) {
    return localStorage.setItem(roleLevelName, role)
}

export function removeToken() {
    return localStorage.removeItem(tokenName)
}

export function getUserId() {
    return localStorage.getItem(userIdName);
}

export function setUserId(id) {
    return localStorage.setItem(userIdName, id);
}

export function getUserInfo() {
    let userInfo = localStorage.getItem(userInfoName);
    return userInfo ? JSON.parse(userInfo) : {};
}

export function setUserInfo(data) {
    if(typeof data == 'object'){
        data = JSON.stringify(data);
    }
    return localStorage.setItem(userInfoName, data)
}

export function getConfig() {
    let config = localStorage.getItem(publicConfigName);
    return config ? JSON.parse(config) : null;
}

export function setConfig(data) {
    if(typeof data == 'object'){
        data = JSON.stringify(data);
    }
    return localStorage.setItem(publicConfigName,data);
}

export function getOfficesList() {
    let list = localStorage.getItem(officesListName);
    return list ? JSON.parse(list) : null;
}

export function setOfficesList(data) {
    if(typeof data == 'object'){
        data = JSON.stringify(data);
    }
    return localStorage.setItem(officesListName, data);
}